package com.zp.io;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;

public class FileWriterTest {
	public static void main(String[] args) throws IOException {
		String str = "zhengpeng hello word welcome jinan";
		
		/**
		 * 使用字符数组的方式：
		 * 定义一个字符数组，将字符串转化成字符数组；
		 */
		char[] bt = new char[str.length()];
		
		/**
		 * str.gerChars():Copies characters from this string 
		 * into the destination character array.
		 */
		str.getChars(0,str.length(),bt,0);
		
		FileWriter fw = new FileWriter("D:/lisi/fileWriter.txt");
		BufferedWriter bw = new BufferedWriter(fw);
		
		for(int i=0;i<str.length();i++){
			bw.write(bt[i]);
		}
		/**
		 * 若使用字符串，如下所示：
		 * 比转化成字符数组简便；
		 */
//		bw.write(str);
		bw.close();
	}
}
